package com.test;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import javax.swing.*;

public class ImagePanel extends JPanel {

    private BufferedImage logo;

    public ImagePanel() {
        try {
            File img = new File("1412.png");
            logo = ImageIO.read(img);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public void paintComponent(Graphics g) {
        g.drawImage(logo,
                20, 20, 200, 270,
                0, 0, logo.getWidth(null), logo.getHeight(null),
                null);
    }

    public static void main(String args[]) {
        JFrame frame = new JFrame("Using Java2D");
        frame.setLayout(new BorderLayout());
        ImagePanel gc = new ImagePanel();
        frame.add(gc, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(280, 320);
        frame.setVisible(true);
    }
}